package com.shuoyue.ycgk.ui.common;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.QuestionNote;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface CollectContract {
    interface View extends BaseView {
        void addCollectSuc();

        void deleteCollectSuc();
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void saveCollect(int questionId,int type) {
            apply(model.saveCollect(questionId,type))
                    .subscribe(new ApiSubscriber<Optional<String>>(mView, this) {
                        @Override
                        public void onNext(Optional<String> dayTagetOptional) {
                            super.onNext(dayTagetOptional);
                            mView.addCollectSuc();
                        }
                    });
        }

        public void deleteCollection(int questionId,int type) {
            apply(model.deleteCollection(questionId,type))
                    .subscribe(new ApiSubscriber<Optional<String>>(mView, this) {
                        @Override
                        public void onNext(Optional<String> dayTagetOptional) {
                            super.onNext(dayTagetOptional);
                            mView.deleteCollectSuc();
                        }
                    });
        }

    }

    class Model extends BaseModel {
        Observable<BaseResult<String>> saveCollect(int questionId,int type) {
            return RetrofitClient.getInstance().getApi().saveCollect(questionId,type);
        }

        Observable<BaseResult<String>> deleteCollection(int questionId,int type) {
            return RetrofitClient.getInstance().getApi().deleteCollection(questionId,type);
        }

    }
}
